﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-10 12:14:26
// 负责人：Sushee
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
namespace OF.Component.DAL
{
	
	/// <summary>
	/// 数据访问层
	/// </summary>	
	internal partial class BaseLocation
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个
    	/// </summary>
        public BaseLocationInfo QuerySingle(Expression<Func<BaseLocationInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取列表
    	/// </summary>
	    public IList<BaseLocationInfo> QueryList(Expression<Func<BaseLocationInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 地理类型的最大ID
        /// </summary>
        /// <param name="locationParentID"></param>
        /// <param name="geographyTypeID"></param>
        /// <returns></returns>
        public int GetGeographyTypeMaxId(int locationParentID, int geographyTypeID)
        {
            int nReturn = 0;
            string szSql = @"SELECT ISNULL(MAX(LocationID),0)
                               FROM [BaseLocation] where [LocationParentID]=@LocationParentID and LocationGeographyTypeID=@LocationGeographyTypeID";
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(szSql);
            db.AddInParameter(dbc, "@LocationParentID", DbType.Int32, locationParentID);
            db.AddInParameter(dbc, "@LocationGeographyTypeID", DbType.Int32, geographyTypeID);
            try
            {
                object o = db.ExecuteScalar(dbc);
                if (o != null)
                {
                    nReturn = Convert.ToInt32(o);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return nReturn;
        }

    }
	
}